package jp.eisbahn.mgapi.api;

import java.util.ArrayList;
import java.util.List;

import jp.eisbahn.mgapi.http.HttpResponse;

public abstract class Response {

    private List<Model> entries;
    
    public Response() {
        super();
    }
    
    protected void setEntries(List<Model> entries) {
        this.entries = entries;
    }
    
    protected void addEntry(Model entry) {
        if (entries == null) {
            entries = new ArrayList<Model>();
        }
        entries.add(entry);
    }
    
    @SuppressWarnings("unchecked")
    public <T extends Model> List<T> getEntries() {
        return (List<T>)entries;
    }
    
    @SuppressWarnings("unchecked")
    public <T extends Model> T getEntry() {
        if (entries == null || entries.size() == 0) {
            return null;
        } else {
            return (T)entries.get(0);
        }
    }

    public abstract void parseResponse(HttpResponse httpResponse);
    
}
